package self.niu.com.resume.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

import java.util.List;

import self.niu.com.resume.R;
import self.niu.com.resume.db.User;
import self.niu.com.resume.ui.MyUtils;

/**
 * Created by Administrator on 2015/9/26.
 */
public class UserListAdapter extends MyBaseAdapter {
    private List<User> list;
    private boolean ischage;

    public UserListAdapter(Context context, List list, boolean ischange) {
        super(context, list);
        this.list = list;
        this.ischage = ischange;
    }

    @Override
    public View getItemView(int position, View view, ViewGroup parent) {
        ViewHolder vh;
        if (view == null) {
            view = inflate.inflate(R.layout.list_show_layout, null);
            vh = new ViewHolder(view);
            view.setTag(vh);
        } else {
            vh = (ViewHolder) view.getTag();
        }

        User user = (User) list.get(position);
        vh.title.setText(user.getTitle());
        vh.content.setText(user.getContent());
        vh.image.setImageResource(MyUtils.getImage(user.getImgUrl()));
        if (ischage) {
            vh.change.setVisibility(View.VISIBLE);
        }
        return view;
    }

    public static class ViewHolder {
        @ViewInject(R.id.list_title_tv)
        private TextView title;
        @ViewInject(R.id.list_content_tv)
        private TextView content;
        @ViewInject(R.id.list_pic_img)
        private ImageView image;
        @ViewInject(R.id.list_change_tv)
        private TextView change;

        public ViewHolder(View view) {
            ViewUtils.inject(this, view);
        }
    }
}
